package com.wzxy.medical_backed.entity;

public class Result<T> {
    private String message;
    private T data;
    private int code;

    public Result() {
    }

    public Result(String message, T data, int code) {
        this.message = message;
        this.data = data;
        this.code = code;
    }

    // Static method for success responses
    public static <T> Result<T> success(T data) {
        return new Result<>("Operation successful", data, 200);
    }

    // Static method for success responses with a custom message
    public static <T> Result<T> success(String message, T data) {
        return new Result<>(message, data, 200);
    }

    // Static method for failure responses
    public static <T> Result<T> fail(String message) {
        return new Result<>(message, null, 500); // Using 500 as a generic error code
    }

    // Static method for failure responses with a custom code and message
    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(message, null, code);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "Result{" +
                "message='" + message + '\'' +
                ", data=" + data +
                ", code=" + code +
                '}';
    }
}
